import os

from mako.template import Template
from mako.lookup import TemplateLookup
from mako import exceptions

current_dir = os.path.abspath('.')
lookup = TemplateLookup(directories=[os.path.join(current_dir, 'templates')], module_directory=os.path.join(current_dir, 'tmp', 'mako_modules'),
                        input_encoding='utf-8', output_encoding='utf-8', encoding_errors='replace', default_filters=['decode.utf8'])

def serve_template(templatename, **kwargs):
    template = lookup.get_template(templatename)
    try:
        return template.render(**kwargs)
    except:
        return exceptions.html_error_template().render()


		